home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / Resource / Init / gs_fntem.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  11.4 KB  |  433 lines

  1. %    Copyright (C) 2000 Artifex Software, Inc.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_fntem.ps 8954 2008-08-08 04:22:38Z ray $
  14. % A procset for Postscript font emulation
  15.  
  16. % The procedures must not depend on the presence of the
  17. % procset dictionary on the dictionary stack.
  18.  
  19. languagelevel 2 .setlanguagelevel
  20.  
  21. %========================= Process xlatmap ====================
  22. mark
  23. %% Replace 1 (xlatmap)
  24. (xlatmap) .runlibfile
  25. .dicttomark dup systemdict exch /.xlatmap_dict exch put
  26.  
  27. % Convert it into a plain text to simplify the processing in C :
  28. % *(fontkind\0\0\ *(charmap\0decoding\0) ) \0
  29.  
  30. () exch {
  31.   3 1 roll =string cvs concatstrings (\0\0) concatstrings
  32.   exch
  33.   { =string cvs concatstrings (\0) concatstrings
  34.   } forall
  35. } forall
  36. (\0) concatstrings
  37. systemdict exch /.xlatmap exch put
  38.  
  39. /FontEmulationProcs 10 dict begin
  40.  
  41. %-------------------------------Font--------------------------------
  42.  
  43.  
  44. /FontCommon  % - font_common -
  45. { currentdict /PaintType known not {
  46.     /PaintType 0 def
  47.   } if
  48.   currentdict /Encoding .knownget not {
  49.     //StandardEncoding
  50.   } if
  51.   dup type /nametype eq {
  52.     /Encoding findresource
  53.   } if
  54.   /Encoding exch def
  55. } bind def
  56.  
  57. /FontOptions 5 dict begin
  58.   /make_procs currentdict def
  59.   /NameKey /FontName def
  60.   /TypeKey /FontType def
  61.  
  62.   1
  63.   { /FontMatrix [0.001 0 0 0.001 0 0] def
  64.     /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  65.     /Private 0 dict def
  66.     /CharStrings << /.notdef () >> def
  67.     //FontCommon exec
  68.   } bind def
  69.  
  70.   42
  71.   { /FontMatrix [1 0 0 1 0 0] def
  72.     /FontBBox [0 0 1 1] def % zfapi.ps refines it.
  73.     /CharStrings <<>> def
  74.     /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  75.     /GlyphDirectory [] def
  76.     //FontCommon exec
  77.   } bind def
  78.  
  79.   %fixme : more font types.
  80.  
  81. currentdict end def
  82.  
  83. %---------------------------CIDFont---------------------------
  84.  
  85. /TranslateCSI   % <record> TranslateCSI <CSI>
  86. { RESMPDEBUG { (fntem TranslateCSI beg ) = } if
  87.   begin
  88.   CSI length 2 eq {
  89.     << /Registry (Adobe) 
  90.        /Ordering CSI aload pop 
  91.        /Supplement exch 
  92.     >>
  93.   } {
  94.     << /Registry CSI 0 get
  95.        /Ordering CSI 1 get
  96.        /Supplement CSI 2 get
  97.     >>
  98.   } ifelse
  99.   end
  100.   RESMPDEBUG { (fntem TranslateCSI end ) = } if
  101. } bind def
  102.  
  103. /CIDFontCommon
  104. { /CIDSystemInfo currentdict //TranslateCSI exec def
  105.   currentdict /CSI undef
  106.   /FontBBox [-128 -128 1024 1024] def % zfapi.ps refines it.
  107.   /CIDCount 1 def % ChooseDecoding will set a reasonable value.
  108. } bind def
  109.  
  110. % GFlyph substitution table for narrow, wide, proportional glyphs - 
  111. % used with TrueTypes.
  112.  
  113. currentpacking false setpacking
  114. /SubstNWP << 
  115.  
  116.   % Array format : orig_type, beg_CID, end_CID, subst_beg_CID, subst_type
  117.   % type = (n==narrow, w==wide, p==proportional).
  118.  
  119.   /Japan1
  120.   { p 1 94 231 n    
  121.  
  122.     p 17 26 780 w
  123.     p 34 59 790 w
  124.     p 66 91 816 w
  125.     w 842 842 7918 w  % fixme: These substitutions require to shift the glyph origin.
  126.     w 844 844 7919 w
  127.     w 846 846 7920 w
  128.     w 848 848 7921 w
  129.     w 850 850 7922 w
  130.     w 876 876 7923 w
  131.     w 908 908 7924 w
  132.     w 910 910 7925 w
  133.     w 912 912 7926 w
  134.     w 914 914 7927 w
  135.     w 925 925 7928 w
  136.     w 927 927 7929 w
  137.     w 929 929 7930 w
  138.     w 931 931 7931 w
  139.     w 933 933 7932 w
  140.     w 959 959 7933 w
  141.     w 991 991 7934 w
  142.     w 993 993 7935 w
  143.     w 995 995 7936 w
  144.     w 1002 1002 7937 w
  145.     w 1009 1009 7938 w
  146.     w 1010 1010 7939 w
  147.   } cvlit
  148.  
  149.   /Japan2 1 index
  150.  
  151.   /CNS1
  152.   { p 1 94 13648 n
  153.  
  154.     p 17 26 333 w
  155.     p 34 59 365 w
  156.     p 66 91 391 w
  157.   } cvlit
  158.  
  159.   /GB1
  160.   { p 2 94 814 n
  161.   
  162.     p 2 94 262 w
  163.  
  164.     p 1 1 7716 n
  165.   } cvlit
  166.  
  167.   /Korea1
  168.   { p  1 60 8094 n
  169.     p 62 94 8155 n
  170.  
  171.     p  2 59 264 w
  172.     p 63 94 325 w
  173.   } cvlit
  174.  
  175.   /Identity []
  176.  
  177.   /Unicode []
  178.  
  179. >> def
  180. setpacking
  181.  
  182. /CIDFontOptions 5 dict begin
  183.   /make_procs currentdict def
  184.   /NameKey /CIDFontName def
  185.   /TypeKey /CIDFontType def
  186.  
  187.   0
  188.   { //CIDFontCommon exec
  189.     /FDArray [
  190.       14 dict begin
  191.         /FontName CIDFontName =string cvs (%) concatstrings cvn def
  192.         /FontType 1 def
  193.         /FontMatrix [0.001 0 0 0.001 0 0 ] def
  194.         /PaintType 0 def
  195.         /Private 0 dict def
  196.         currentdict
  197.       end
  198.     ] def
  199.     /GlyphDirectory [] def
  200.     /GDBytes 1 def
  201.     /FDBytes 0 def
  202.   } bind def
  203.  
  204.   1
  205.   { //CIDFontCommon exec
  206.     /FontMatrix [1 0 0 1 0 0] def
  207.     /BuildGlyph {} def
  208.   } bind def
  209.  
  210.   2
  211.   { //CIDFontCommon exec
  212.     /FontMatrix [1 0 0 1 0 0] def
  213.     /GDBytes 2 def
  214.     /CIDMap <0000> def
  215.     /sfnts [<00010000 0000 0000 0000 0000 0000>] def
  216.     /Encoding [] def
  217.     /CharStrings << /.notdef 0 >> def
  218.   } bind def
  219.  
  220. currentdict end def
  221.  
  222. /complete_instance  % <font_name> <FontDict> <Options> complete_FAPI_Font <font_name> <FontDict>
  223. { begin
  224.   dup length dict copy
  225.   begin
  226.   dup type /nametype ne { cvn } if
  227.   dup NameKey exch def
  228.   currentglobal true setglobal
  229.   make_procs TypeKey load .knownget {
  230.     exec
  231.   } { setglobal
  232.       /complete_instance cvx /invalidfont signalerror
  233.   } ifelse
  234.   setglobal
  235.   currentdict end
  236.   end
  237. } bind def
  238.  
  239. /GetFilePath    % <scratch> <Name> <record> GetFilePath <filepath>
  240. { exch pop                       % (scratch) <record>
  241.   /Path get                      % (scratch) (path)
  242.   exch copy
  243.   % What we make here it is not a complete PS resource.
  244.   % Unable to provide full conformity :
  245.   % the attempt to run this file may fail.
  246. } bind def
  247.  
  248. /GetSize        % <Name> <record> GetSize <size>
  249. { pop pop -1 % Unknown size.
  250.   % fixme: probably we could provide an estimation size for some fonts.
  251. } bind def
  252.  
  253. /RecordVirtualMethodsStub 3 dict begin
  254.   /GetFilePath //GetFilePath def
  255.   /GetSize //GetSize def
  256. currentdict end def
  257.  
  258. % ---------------------- Decoding helpers ----------------------------
  259.  
  260. /encodingnames mark
  261.  StandardEncoding /StandardEncoding
  262.  ISOLatin1Encoding /ISOLatin1Encoding
  263.  SymbolEncoding /SymbolEncoding
  264.  DingbatsEncoding /DingbatsEncoding
  265.  /resourceforall where {
  266.    pop (*) { dup cvn
  267.      EncodingDirectory exch .knownget not {
  268.        % A work around bug 688710 on Linux :
  269.        % findencoding can't load resource files until gs_init.ps executes .fixresources . 
  270.        % It will happen after gs_init.ps runs INITFILES,
  271.        % from which the current file runs.
  272.        % Windows build has no such problem.
  273.        (.svn) anchorsearch {
  274.          % HACK : skip .svn or */* names, which are subdirectories.
  275.          pop pop
  276.        } {
  277.          (/) search {
  278.            pop pop pop
  279.          } {
  280.            cvn dup /Encoding findresource
  281.          } ifelse
  282.        } ifelse
  283.      } {
  284.        exch cvn exch
  285.      } ifelse
  286.      exch 
  287.    } 1024 string /Encoding resourceforall 
  288.  } if
  289. .dicttomark def
  290.  
  291. /ChooseDecoding  % <font> ChooseDecoding <font>
  292. { { % A loop for 'exit' context.
  293.     dup /Decoding .knownget {
  294.       dup type /nametype eq {
  295.         1 index /CIDFontType known { /CIDDecoding } { /Decoding } ifelse
  296.         findresource 1 index exch /Decoding exch put
  297.       } {
  298.         pop
  299.       } ifelse
  300.       dup /CIDFontType known {
  301.         dup dup /Decoding get /CIDCount get /CIDCount exch put
  302.       } if
  303.       exit
  304.     } if
  305.     dup /CIDFontType known {
  306.       % This is a hooked CID font, no need for Decoding.
  307.       exit
  308.     } if
  309.     % This works when the renderer can't choose character by name,
  310.     % and we cannot determine the charset.
  311.     % Probably this branch is to be removed after UFST problem is fixed.
  312.     dup /Encoding get                                    % <<font>> encoding
  313.     dup type /nametype eq {
  314.       /Decoding findresource 1 index exch /Decoding exch put
  315.     } {
  316.       dup //encodingnames
  317.       exch .knownget {
  318.         exch pop
  319.         /Decoding findresource 1 index exch /Decoding exch put
  320.       } {
  321.         % unknown encoding, convert it to decoding :
  322.         dup length dict begin
  323.         /.notdef 0 def
  324.         0 1 currentdict length 1 sub
  325.         { dup 2 index exch get 
  326.           dup /.notdef ne {
  327.             exch def
  328.           } {
  329.             pop pop
  330.           } ifelse
  331.         } for
  332.         pop
  333.         currentdict end
  334.         1 index exch /Decoding exch put
  335.       } ifelse
  336.     } ifelse
  337.     exit
  338.   } loop
  339.   dup /CIDFontType known {
  340.     dup /SubstNWP .knownget not {
  341.       dup /CIDSystemInfo get /Ordering get cvn
  342.     } if
  343.     dup type /nametype eq {
  344.       //SubstNWP exch .knownget not {
  345.         []
  346.       } if                                   % <<font>> [SubstNWP]
  347.     } if
  348.     1 index exch /SubstNWP exch put
  349.   } if
  350. } bind def
  351.  
  352. /PrintFontRef      % <string|name> <font> PrintFontRef <string|name> <font>
  353. { dup /FontName known { (Font ) } { (CIDFont ) } ifelse print
  354.   1 index =string cvs print
  355.   dup /FontName .knownget not {
  356.     dup /CIDFontName get
  357.   } if                               % <string|name> <font> <fontname>
  358.   dup 3 index ne {
  359.     ( \( aliased from ) print
  360.     =string cvs print ( \)) print
  361.   } {
  362.     pop
  363.   } ifelse
  364. } bind def
  365.  
  366. /GetFontType       % <font> GetFontType int
  367. { dup /CIDFontType .knownget {
  368.     exch pop 9 add
  369.   } {
  370.     /FontType get
  371.   } ifelse
  372. } bind def
  373.  
  374. /FindInArray    % <array> <elem> .array_find <bool>
  375. { false 3 1 roll
  376.   exch {                      % false elem elem_i
  377.     1 index eq {              % false elem
  378.        pop true exch
  379.     } if
  380.   } forall
  381.   pop
  382. } bind def
  383.  
  384. /ProvideUnicodeDecoding % <font> ProvideUnicodeDecoding <font>
  385. {
  386.   % If the font is maintained by FAPI, or if it is TT-emulated CID font,
  387.   % it already has /Decoding. But its value isn't guaranteeed to
  388.   % be an Unicode decoding. Since we can't determine whether 
  389.   % it is an Unicode decoding, we unconditionally load an appropriate Unicode decoding
  390.   % and attach it with /GlyphNames2Unicode entry.
  391.   %
  392.   % Another interesting case is when the font already has /GlyphNames2Unicode.
  393.   % The latter to be used instead. Note that /GlyphNames2Unicode
  394.   % appears only when type 32 fonts are disable (see .pdf_hook_DSC_Creator),
  395.   % but an automatic disabling is not implemented yet.
  396.  
  397.   currentglobal true setglobal exch
  398.   dup /FontInfo known not {
  399.     dup /FontInfo 1 dict put
  400.   } if
  401.   { % A loop just for 'exit' context.
  402.     dup /FontInfo get /GlyphNames2Unicode known {
  403.       exit
  404.     } if
  405.     dup /CIDFontType known {
  406.       dup mark exch                                              % bool <font> [ <font>
  407.       dup /CIDSystemInfo get /Ordering get (.Unicode)            % bool <font> [ <font> () ()
  408.       concatstrings cvn                                          % bool <font> [ <font> /Name
  409.       /CIDDecoding { findresource } stopped {
  410.         % Can't provide a decoding, giving up without creating /GlyphNames2Unicode.
  411.         cleartomark exit
  412.       } if                                                       % bool <font> [ <font> <D>
  413.       exch /FontInfo get exch                                    % bool <font> [ <FI> <D>
  414.       /GlyphNames2Unicode exch
  415.       .forceput % FontInfo can be read-only.
  416.       pop                                                        % bool <font>
  417.       exit
  418.     } if
  419.     dup /FontInfo get                                            % bool <font> <FI>
  420.     /GlyphNames2Unicode /Unicode /Decoding findresource
  421.     .forceput % FontInfo can be read-only.
  422.     exit
  423.   } loop
  424.   exch setglobal
  425. } bind def
  426.  
  427. currentdict end /ProcSet defineresource pop
  428.  
  429. .setlanguagelevel
  430.